import hashlib
import random
import datetime


def random_nums():
    """随机生成 6位验证码"""
    s = ""
    for i in range(6):
        ch = chr(random.randrange(ord('0'), ord('9') + 1))
        s += ch

    return s


def get_account_expire_time(expire_time: datetime):
    """计算申请账户剩余时间"""
    now = datetime.datetime.now()
    days = (expire_time - now).days

    return days


def query_params(query_conditions):
    """计算路由器要查询的条件"""
    params = dict()
    for k, v in query_conditions.items():
        if v:
            params.update({k: v.strip()})

    return params


def pwd_to_md5(pwd):
    """
    密码 md5 加密
    :param pwd: 密码
    :return: md5 值
    """
    m = hashlib.md5()
    pwd_bytes = pwd.encode('utf-8')
    m.update(pwd_bytes)

    return m.hexdigest()


if __name__ == '__main__':
    pass
